package com.gin.kotlin.no_gay_alliance.provider.ngaphp

import com.gin.kotlin.no_gay_alliance.model.CheckInStatusModel
import com.gin.nga.main.NgaApi
import com.gin.nga.response.checkin.CheckInBody
import java.lang.ref.WeakReference

class CheckInStatusProvider private constructor() : AbstractCachedDataProvider<Nothing, CheckInBody, CheckInStatusModel>(
    javaType = TYPE_FACTORY.constructType(CheckInStatusModel::class.java),
) {
    override val dir = "CHECK_IN_STATUS"

    override fun transform(rawData: CheckInBody) = CheckInStatusModel(rawData)

    override fun requestMethod(ngaApi: NgaApi, params: Nothing?) = ngaApi.accountApi.checkInGet()

    override fun obtainRelativePath(userId: Long, params: Nothing?) = "$userId.json"

    companion object {
        private var instance: WeakReference<CheckInStatusProvider> = WeakReference(CheckInStatusProvider())
        fun getInstance(): CheckInStatusProvider = instance.get() ?: CheckInStatusProvider().also { instance = WeakReference(it) }
    }
}